<template>
  <div class="wrapper">
    <div class="header">知识点列表</div>
    <div style="border-bottom: 1px solid #ccc; margin-bottom: 0.2rem">
      <el-checkbox
        v-model="checkAll"
        :indeterminate="isIndeterminate"
        @change="handleCheckAllChange"
        size="large"
      >
        全选
      </el-checkbox>
    </div>
    <div class="scroll-wrapper">
      <el-scrollbar>
        <el-checkbox-group
          class="points"
          v-model="checkedKnowledgePoints"
          @change="handleCheckedKnowledgePointsChange"
        >
          <el-checkbox
            size="large"
            v-for="point in knowledgePoints"
            :key="point"
            :label="point"
            :value="point"
          >
            {{ point }}
          </el-checkbox>
        </el-checkbox-group>
      </el-scrollbar>
    </div>

    <el-button class="btn" color="#43b883" :dark="selected">生成</el-button>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const checkAll = ref(false)
const isIndeterminate = ref(false)

const knowledgePoints = ['解含括号的方程', '解小数方程', '解分数方程']
const checkedKnowledgePoints = ref([])

const handleCheckAllChange = (val) => {
  checkedKnowledgePoints.value = val ? knowledgePoints : []
  isIndeterminate.value = false
}
const handleCheckedKnowledgePointsChange = (value) => {
  const checkedCount = value.length
  checkAll.value = checkedCount === knowledgePoints.length
  isIndeterminate.value = checkedCount > 0 && checkedCount < knowledgePoints.length
}
</script>

<style lang="scss" scoped>
.wrapper {
  font-size: 20px;
  height: calc(100vh - 60px);
  padding-top: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;

  .header {
    height: 50px;
    line-height: 50px;
    font-size: 20px;
    font-weight: 700;
  }

  .scroll-wrapper {
    height: 100%;
  }
  .btn {
    width: 100%;
    font-size: 18px;
    color: #fff;
    height: 40px;
    box-sizing: border-box;
    margin-bottom: 40px;
  }
}
</style>
